﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PlcUI_test.MyControls
{
    public partial class StatusPanelButtons : UserControl
    {
        private string _button1Name;
        public string button1Name
        {
            get { return _button1Name; }
            set
            {
                _button1Name = value;
                radioButton1.Text = value;
            }
        }
        private string _button2Name;
        public string button2Name
        {
            get { return _button2Name; }
            set
            {
                _button2Name = value;
                radioButton2.Text = value;
            }
        }
        private string _button3Name;

        public string button3Name1
        {
            get { return _button3Name; }
            set
            {
                _button3Name = value;
                button1.Text = value;
            }
        }

        private string _button4Name;

        public string button4Name1
        {
            get { return _button4Name; }
            set
            {
                _button4Name = value;
                button2.Text = value;
            }
        }
        private string _button5Name;

        public string button5Name1
        {
            get { return _button5Name; }
            set
            {
                _button5Name = value;
                button3.Text = value;
            }
        }

        public event EventHandler Button1Click;
        public event EventHandler Button2Click;
        public event EventHandler Button3Click;
        public event EventHandler Button4Click;
        public event EventHandler Button5Click;


        public bool RadioButton1Checked
        {
            get { return radioButton1.Checked; }
            set { radioButton1.Checked = value; }
        }
        public bool RadioButton2Checked
        {
            get { return radioButton2.Checked; }
            set { radioButton2.Checked = value; }
        }


        public StatusPanelButtons()
        {
            InitializeComponent();
            this.radioButton2.Checked = true;
            this.radioButton2.CheckedChanged += radioButton2_CheckedChanged;
            this.button1.Click += button1_Click;
            this.button2.Click += button2_Click;
            this.button3.Click += button3_Click;     // button被点击触发以下事件
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                radioButton2.Checked = false;
                Button1Click?.Invoke(sender, e); 
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {
                radioButton1.Checked = false;
                Button2Click?.Invoke(sender, e);
            }
        }

        // 外界调用的
        public void button1Click(object sender, EventArgs e)
        {
            Button3Click?.Invoke(sender, e);
        }
        public void button2Click(bool value)
        {
            radioButton2.Checked = value;
            
        }


        private void button1_Click(object sender, EventArgs e)
        {
            Button3Click?.Invoke(sender, e);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Button4Click?.Invoke(sender, e);
        }
        private void button3_Click(object sender, EventArgs e)
        {
            Button5Click?.Invoke(sender, e);
        }

    }
}
